package common

import (
	"encoding/json"

	"github.com/gin-gonic/gin"

	"github.com/gin-contrib/sessions"
)

type UserSession struct {
	Id   int64  `json:"id"`
	Name string `json:"name"`
}

func (us UserSession) GetUserInfo(c *gin.Context) UserSession {
	session := sessions.Default(c)
	userInfo := session.Get("user")
	jsonStrByte := []byte(userInfo.(string))
	decodeData := us
	json.Unmarshal(jsonStrByte, &decodeData)
	return decodeData
}
